package cn.stronglink.assetmanage.business.inspection.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.RepailDetail;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 资产列表
 * Created by zhengjinglan on 2018/6/20.
 */

public class RegisterOrderAdapter extends RecyclerView.Adapter<RegisterOrderAdapter.ViewHolder>{
    private Context mContext;
    private List<RepailDetail> datas;
    private onRecyclerListener listener;

    public RegisterOrderAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public RegisterOrderAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_repair_wait_list, null);
        return new RegisterOrderAdapter.ViewHolder(view, listener);
    }

    @Override
    public void onBindViewHolder(RegisterOrderAdapter.ViewHolder holder, int position) {
        RepailDetail asset = datas.get(position);
        holder.bindRepo(asset, position);
    }

    @Override
    public int getItemCount() {

        return datas == null ? 0 : datas.size();
    }

    public void setOnItemClickListener(onRecyclerListener listener) {
        this.listener = listener;
    }

    public void notifyDatasChanged(List<RepailDetail> data) {
        this.datas = data;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        private final TextView tv_repair_wait_asset_name;
        private final TextView tv_repair_wait_sn;
        private final TextView tv_repair_wait_bind_status;
        private onRecyclerListener listener;

        public ViewHolder(View itemView, onRecyclerListener listener) {
            super(itemView);
            this.listener = listener;
            tv_repair_wait_asset_name = (TextView)itemView.findViewById(R.id.tv_repair_wait_asset_name);
            tv_repair_wait_sn = (TextView)itemView.findViewById(R.id.tv_repair_wait_sn);
            tv_repair_wait_bind_status = (TextView)itemView.findViewById(R.id.tv_repair_wait_bind_status);
        }

        public void bindRepo(RepailDetail repo, int position) {
            tv_repair_wait_asset_name.setText(repo.getAssetName());
            tv_repair_wait_sn.setText(repo.getSerialNo());
            int bindStatus = repo.getStatus();
            if(bindStatus== Constants.STATUS_THREE){
                tv_repair_wait_bind_status.setText(mContext.getResources().getString(R.string.common_unrepair));
                tv_repair_wait_bind_status.setTextColor(mContext.getResources().getColor(R.color.un_bind_red));
            }else{
                tv_repair_wait_bind_status.setText(mContext.getResources().getString(R.string.common_repair));
                tv_repair_wait_bind_status.setTextColor(mContext.getResources().getColor(R.color.bind_green));
            }

        }

        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.onItemClicked(v, getAdapterPosition());
            }
        }
    }
}
